<#macro head title="Snapex 移动报销"> 
<#compress>
  <head>  
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <#-- HTTP 1.1 -->
	<meta http-equiv="pragma" content="no-cache">
	<#-- HTTP 1.0 -->
	<meta http-equiv="cache-control" content="no-cache">
	<#-- Prevent caching at the proxy server -->
	<meta http-equiv="expires" content="0">
	<title>${title}</title>
    <#-- Bootstrap -->
    <link href="/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <#-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <#-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
      <script src="/bootstrap-3.3.7/js/html5shiv-3.7.3.min.js"></script>
      <script src="/bootstrap-3.3.7/js/respond-1.4.2.min.js"></script>
    <![endif]-->
    
     <link href="/bootstrap-table-1.2.1/bootstrap-table.css" rel="stylesheet" />
     
    <#-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="/bootstrap-3.3.7/js/jquery-1.12.4.min.js"></script>
    <#-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="/bootstrap-table-1.2.1/bootstrap-table.js"></script>
    <script src="/bootstrap-table-1.2.1/locale/bootstrap-table-zh-CN.js"></script>
    
    <script type="text/javascript" src="/knockout-3.4.2.js"></script>
	<#--<script type="text/javascript" src="/jquery-3.3.1.min.js"></script> -->	     
	
	<#-- 
	<script type="text/javascript" src="/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
	<link href="/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css" rel="stylesheet">
	 -->
	 
	<style type="text/css">
	.ko-table { margin-bottom: 1em; width: 25em; border: 1px solid silver; background-color:white; }
	.ko-table th { text-align:left; background-color: red; color:white; font-style:bold}
	.ko-table td, th { padding: 0.4em; }
	.ko-table tr:nth-child(odd) { background-color: #DDD; }
	.ko-table-pageLinks { margin-bottom: 1em; }
	.ko-table-pageLinks a { padding: 0.5em; }
	.ko-table-pageLinks a.selected { background-color: black; color: white; }
	</style>
  </head>
</#compress>
</#macro>

<#macro html class="" style="margin:1em 2em 0 2em"> 
<!DOCTYPE html>
<html lang="zh-CN">
<@head/>  
<body class="${class}" style="${style}">
<#nested/>
</body>
</html>
</#macro>

<#macro _koExtenders>
<#compress>
<#-- https://knockoutjs.com/documentation/extenders.html -->
<#-- Forcing input to be numeric 

this.myNumberOne = ko.observable(1234).extend({ numeric: 2 });

-->
<#-- 
ko.extenders.numeric = function(target, precision) {
    //create a writable computed observable to intercept writes to our observable
    var result = ko.pureComputed({
        read: target,  //always return the original observables value
        write: function(newValue) {
            var current = target(),
                roundingMultiplier = Math.pow(10, precision),
                newValueAsNum = isNaN(newValue) ? 0 : +newValue,
                valueToWrite = Math.round(newValueAsNum * roundingMultiplier) / roundingMultiplier;
 
            //only write if it changed
            if (valueToWrite !== current) {
                target(valueToWrite);
            } else {
                //if the rounded value is the same, but a different value was written, force a notification for the current field
                if (newValue !== current) {
                    target.notifySubscribers(valueToWrite);
                }
            }
        }
    }).extend({ notify: 'always' });
 
    //initialize with current value to make sure it is rounded appropriately
    result(target());
 
    //return the new computed observable
    return result;
};

ko.extenders.undefinedIfBlank = function (target, option) {
    if (option) {
        var oldValue;
        target.subscribe(function(currentValue){
            oldValue = currentValue;
        }, null, 'beforeChange');
        
        target.subscribe(function (newValue) {
                if (newValue !== oldValue) {                    
                    if (typeof newValue === "string" && newValue.length == 0) {
                        target(undefined);
                        target.notifySubscribers(undefined);
                    } else {            
                        target(newValue);
                    }
                } else {
                    //do nothing?
                }
        });
        
        return target;
    }

    return target;
};
 -->
<#-- 
ko.subscribable.fn.subscribeChanged = function (callback) {
    var oldValue;
    this.subscribe(function (_oldValue) {
        oldValue = _oldValue;
    }, this, 'beforeChange');

    this.subscribe(function (newValue) {
        callback(newValue, oldValue);
    });
};
-->
ko.subscribable.fn.valueChanged = function (callback) {
    var savedValue = this.peek();
    return this.subscribe(function (newValue) {
        var oldValue = savedValue;
        savedValue = newValue;
        callback(oldValue,newValue);
    });
};
<#-- https://github.com/ericmbarnard/Knockout-Validation -->
<#-- 
https://github.com/adamwdraper/Numeral-js 
http://openexchangerates.github.io/accounting.js/
-->

Date.prototype.Format = function(fmt){
	var o = {
		 "M+": this.getMonth()+1,
		 "d+": this.getDate(),
		 "H+": this.getHours(),
		 "m+": this.getMinutes(),
		 "s+": this.getSeconds(),
		 "S+": this.getMilliseconds()
	};
	
	if(/(y+)/.test(fmt)){
		fmt=fmt.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length));
	}
	
	for(var k in o){
		if (new RegExp("(" + k +")").test(fmt)){
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(String(o[k]).length)));			
		}
	}	
	return fmt;
}
</#compress>
</#macro>

<#macro koExtenders>
    <script type="text/javascript">    	
    	<@_koExtenders/>
	</script>
</#macro>
